<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('系统租户列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>租户名称：</label>
                                <input type="text" name="tenantName"/>
                            </li>
                            <li>
                                <label>租户状态：</label>
                                <select name="tenantStatus" th:with="type=${@dict.getType('sys_tenant_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:tenant:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:tenant:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:tenant:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:tenant:remove')}]];
        var tenantStatusDatas = [[${@dict.getType('sys_tenant_status')}]];
        var prefix = ctx + "system/tenant";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "系统租户",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'tenantId',
                    title: '租户id'
                },
                {
                    field: 'tenantName',
                    title: '租户名称'
                },
                {
                    field: 'tenantEnIntroduction',
                    title: '租户英文简称'
                },
                {
                    field: 'tenantAddress',
                    title: '租户地址'
                },
                {
                    field: 'tenantIntroduction',
                    title: '租户简介'
                },
                {
                    field: 'tenantBeginTime',
                    title: '租赁开始时间'
                },
                {
                    field: 'tenantEndTime',
                    title: '租赁结束时间'
                }
                // ,
                // {
                //     field: 'tenantStatus',
                //     title: '租户状态',
                //     formatter: function(value, row, index) {
                //        return $.table.selectDictLabel(tenantStatusDatas, value);
                //     }
                // }
                    ,
                    {
                        visible: editFlag == 'hidden' ? false : true,
                        title: '租户状态',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return statusTools(row);
                        }
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.tenantId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function statusTools(row) {
            if (row.tenantStatus == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.tenantId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.tenantId + '\')"></i> ';
            }
        }


        /* 租户管理-停用 */
        function disable(tenantId) {
            $.modal.confirm("确认要停用该租户吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "tenantId": tenantId, "status": 1 });
            })
        }

        /* 租户管理启用 */
        function enable(tenantId) {
            $.modal.confirm("确认要启用该租户吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "tenantId": tenantId, "status": 0 });
            })
        }
    </script>
</body>
</html>